const app = getApp();
const companyName = app.globalData.companyName;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    name: '',
    phone: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },
  setName: function(e) {
    this.setData({
      name: e.detail.value
    });
  },
  setPhone: function(e) {
    this.setData({
      phone: e.detail.value
    });
  },
  save: function() {
    const that = this;
    const name = that.data.name;
    const phone = that.data.phone;
    const url = app.globalData.url;
    wx.request({
      url: url + '/management/addCoach',
      data: {
        companyName,
        name,
        phone
      },
      method: 'POST',
      success: function(response) {
        if (response.data.success) {
          wx.navigateBack({
            delta: 1
          });
          wx.showToast({
            title: '保存成功',
            icon: 'none'
          });
        } else {
          wx.showToast({
            title: '保存失败:' + response.data.message,
            icon: 'none'
          });
        }
      }
    })
  }
})